package ch.ethz.fcl.metrobuzz.controller.gui.twl.treetable;

import de.matthiasmann.twl.ThemeInfo;
import de.matthiasmann.twl.ToggleButton;
import de.matthiasmann.twl.TreeTable;
import de.matthiasmann.twl.Widget;
import de.matthiasmann.twl.model.BooleanModel;

public class CheckBoxCellRenderer implements TreeTable.CellWidgetCreator {
	private BooleanModel model;
	private int cbHeight;

	public Widget updateWidget(Widget existingWidget) {
		ToggleButton tb = (ToggleButton) existingWidget;
		if (tb == null) {
			tb = new ToggleButton();
		}
		tb.setTheme("/checkbox");
		tb.setModel(model);
		tb.setActive(model.getValue());
		return tb;
	}

	public void positionWidget(Widget widget, int x, int y, int w, int h) {
		widget.setPosition(x, y + 1);
		widget.setSize(cbHeight, cbHeight);
	}

	public void applyTheme(ThemeInfo themeInfo) {
		cbHeight = themeInfo.getParameter("cbHeight", 13);
	}

	public String getTheme() {
		return "CheckBoxCellRenderer";
	}

	public void setCellData(int row, int column, Object data) {
		this.model = (BooleanModel) data;
	}

	public int getColumnSpan() {
		return 1;
	}

	public int getPreferredHeight() {
		return cbHeight;
	}

	public Widget getCellRenderWidget(int x, int y, int width, int height,
			boolean isSelected) {
		return null;
	}
}
